<script src='<?php echo DIR_JS?>ui.datepicker.js' type='text/javascript' language='javascript'> </script>
<div class="section" id="sitemaplist">

	<div class="section-title">Quản lý kỳ báo</div>
    
    <div class="section-content padding1">
    
    	<form name="frm" id="frm" action="<?php echo $action?>" method="post" enctype="multipart/form-data">
            <div class="button right">
                <a class="button save" id="saveForm">Lưu</a>
                <a class="button cancel" href="?route=deliman/kybao">Bỏ qua</a>  
                <input type="hidden" id="kybaoid" name="kybaoid" value="<?php echo $item['kybaoid']?>">  
            
        	</div>
        	<div class="clearer">^&nbsp;</div>
        	
        	<div id="error" class="error" style="display:none"></div>
        	<div>   
            	<p>
                    <label>Tên loại báo:</label><br />
                     <select id="loaibaoid" name="loaibaoid">
                    	<?php foreach($loaibaos as $loaibao){ ?>
                        <option value="<?php echo $loaibao['loaibaoid']?>"><?php echo $loaibao['tenloaibao']?></option>
                        <?php } ?>
                    </select>
                </p>
                
                <p>
                    <label>Số kỳ báo:</label><br />
                    <input type="text" id="sokybao"  name="sokybao" value="<?php echo $item['sokybao']?>" class="text" size=10/>
                </p>
               
                <p>
                <label >Tên kỳ báo:</label><br />
                <input type="text" id="tenkybao" name="tenkybao" value="<?php echo $item['tenkybao']?>" class="text" size=60 />
               </p>
                
                 <p>
                    <label>Ngày phát hành:</label><br />
                     <script language="javascript">
						$(function() {
							$("#ngayphathanh").datepicker({
									changeMonth: true,
									changeYear: true,
									dateFormat: 'dd-mm-yy'
									});
							});
					 </script>
                    <input type="text" id="ngayphathanh" name="ngayphathanh" value="<?php echo $this->date->formatMySQLDate($item['ngayphathanh'])?>" class="text" size=60 />
                </p>
                
                 <p>
                    <label>Giá bán:</label><br />
                    <input type="text" name="giaban" value="<?php echo $item['giaban']?>" class="text number" size=60 />
                </p>
                
                 <p>
                    <label>Giá in:</label><br />
                    <input type="text" id="giain" name="giain" value="<?php echo $item['giain']?>" class="text number" size=60 />
                </p>
                
                <p>
                    <label>Chi phí khác:</label><br />
                    <input type="text" id="chiphikhac" name="chiphikhac" value="<?php echo $item['chiphikhac']?>" class="text number" size=60 />
                </p>
                
                <p>
                    <label>Tổng giá gốc:</label><br />
                    <input type="text" id="tonggiagoc" name="tonggiagoc" value="<?php echo $item['tonggiagoc']?>" class="text number" size=60 />
                </p>
                
                <p>
                    <label>Số lượng in:</label><br />
                    <input type="text" name="soluongin" value="<?php echo $item['soluongin']?>" class="text number" size=60 />
                </p>
                
                <p>
                    <label>Số trang:</label><br />
                    <input type="text" name="sotrang" value="<?php echo $item['sotrang']?>" class="text number" size=60 />
                </p>
                
                <p>
                    <label>Ghi chú:</label><br />
                    <textarea cols="58" rows="8" name="ghichu"><?php echo $item['ghichu']?></textarea>
                </p>
                
                
            </div>
            
        </form>
    
    </div>
    
</div>

<script language="javascript">
$(document).ready(function(){
	
	//save form
		$('#saveForm').click(function(){
			 save();
		});

	//load du lieu vao text box	
	if($('#kybaoid').val()=="")
	{
		$.ajax({
			url: '?route=deliman/kybao/getsokybao&loaibaoid='+$('#loaibaoid').val(),
			cache: false,
			success: function(html){
				var obj =jQuery.parseJSON(html);
				$('#sokybao').val( Number(obj.sokybao) +1 );
				var tenkybao = $('#loaibaoid option:selected').text() + " - kỳ " + $('#sokybao').val();
				$('#tenkybao').val(tenkybao);
			}
		});
		
	}

	//load du lieu vao text box khi thay doi combox loai bao
		$('#loaibaoid').change(function(){
			var kybaoid = $('#kybaoid').val();
			if(kybaoid==''){//NHThoai sửa - 14Apr2012
				$.ajax({
				url: '?route=deliman/kybao/getsokybao&loaibaoid='+$('#loaibaoid').val(),
				cache: false,
				success: function(html){
					var obj =jQuery.parseJSON(html);
					$('#sokybao').val( Number(obj.sokybao) +1 );
					var tenkybao = $('#loaibaoid option:selected').text() + " - kỳ " + $('#sokybao').val();
					$('#tenkybao').val(tenkybao);
						}
				});
			}
		});
		
		$('#loaibaoid').change();
		
	//giu lai gia tri tim kiem	
		$("#loaibaoid").val("<?php echo $_GET['loaibaoid']?>");
		$("#kybaoid").val("<?php echo $_GET['kybaoid']?>");
		
		$('#sokybao').keyup(function(){
			var tenkybao = $('#loaibaoid option:selected').text() + " - kỳ " + $('#sokybao').val();
			$('#tenkybao').val(tenkybao);
		});
		
		
		//$('#loaibaoid').change();
		
		$("#loaibaoid").val("<?php echo $_GET['loaibaoid']?>");
	
		<!-- lấy id loại báo load vào form-->
		$('#loaibaoid').val("<?php echo $item['loaibaoid']?>");

	//jquery thay doi tong gia goc
		<!--format gia tri cua gia in-->
		$('#giain').keyup(function(){
			var giain = $('#giain').val().replace(/,/g,"");
			var chiphikhac = $('#chiphikhac').val().replace(/,/g,"");
			var giagoc = Number(giain) + Number(chiphikhac);
			$('#tonggiagoc').val(formateNumber(giagoc));
		});
		
		
		<!--format gia tri cua chi phi khac-->
		$('#chiphikhac').keyup(function(){
			var giain = $('#giain').val().replace(/,/g,"");
			var chiphikhac = $('#chiphikhac').val().replace(/,/g,"");
			var giagoc = Number(giain) + Number(chiphikhac);
			$('#tonggiagoc').val(formateNumber(giagoc));
		});	
});



<!--thực hiện chức năng save dữ liệu-->
function save()
{
	$.blockUI({ message: "<h1>Please wait...</h1>" }); 
	
	$.post("?route=deliman/kybao/save", $("#frm").serialize(),
		function(data){
			if(data == "true")
			{
				window.location = "?route=deliman/kybao";
			}
			else
			{
			
				$('#error').html(data).show('slow');
				$.unblockUI();
				
			}
			
		}
	);
}
</script>
